object SortHelper {
    private fun <E: Comparable<E>> isSort(l: MutableList<E>): Boolean {
        for (i in 1 until l.size) {
            if (l[i] < l[i - 1]) {
                return false
            }
        }
        return true
    }

    fun <E: Comparable<E>> sortTest(sortName: SortName, l: MutableList<E>) {

        val startTime = System.nanoTime()
        when (sortName) {
            SortName.SELECT -> SelectSort.sort(l)
            SortName.INSERT -> InsertSort.sort(l)
            SortName.MERGE -> MergeSort.sort(l)
            SortName.MERGE_FROM_BELOW -> MergeSort.sortFromBelow(l)
            SortName.QUICK -> QuickSort.sort(l)
            SortName.QUICK_THREE_WAYS -> QuickSort.sortThreeWays(l)
        }
        val endTime = System.nanoTime()

        if (isSort(l)) {
            println("${sortName}排序 n=${l.size} 消耗 ${(endTime - startTime) / 1000000000.0} 秒")
        }else {
            println("${sortName}排序 排序失败")
        }
    }
}

enum class SortName {
    SELECT,
    INSERT,
    MERGE,
    MERGE_FROM_BELOW,
    QUICK,
    QUICK_THREE_WAYS
}